<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>资金归集</cite></a>
    <a><cite>营销红包分账</cite></a>
    <a><cite>分账用户</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">分账用户列表</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row">
            <div class="layui-form" style="float:right;">
              <div class="layui-form-item" style="margin:0;">
                <div class="layui-input-inline">
                  <input type="text" name="searchId" id="searchId" placeholder="ID" autocomplete="off" class="layui-input">
                </div>
                <a id="search" class="layui-btn" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</a>
              </div>
            </div>
          </div>
          <div class="layui-row">
            <div class="layuiAdmin-btns" style="margin-bottom: 10px;">
              <a class="layui-btn create" data-events="create"><i class="layui-icon layui-icon-add-1"></i>新增</a>
            </div>
          </div>
          <div class="layui-row">
            <div class="layuiAdmin-btns" style="margin-bottom: 10px;"></div>
          </div>
          <table id="XxPay_Mgr_Alipay_Cash_User_dataAll" lay-filter="XxPay_Mgr_Alipay_Cash_User_dataAll"></table>
        </div>

      </div>
    </div>
  </div>
</div>

<script type="text/html" id="xxpayBar">
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view"><i class='layui-icon layui-icon-about'></i>查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class='layui-icon layui-icon-edit'></i>编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script>
  layui.use(['admin', 'table', 'util'], function(){
    var $ = layui.$
      ,admin = layui.admin
      ,table = layui.table
      ,element = layui.element
      ,view = layui.view
      ,form = layui.form;

    element.render('breadcrumb', 'breadcrumb');

    var tplStatus = function(d){
      if(d.status == 1) {
        return "<span style='color: green'>正常分账</span>";
      }else if(d.status == 0) {
            return "<span style='color: red'>暂停分账</span>";
      }else if(d.status == 2) {
            return "<span style='color: red'>金额限制分账</span>";
      }
    };

    //商户列表
    table.render({
      elem: '#XxPay_Mgr_Alipay_Cash_User_dataAll'
      ,url: layui.setter.baseUrl + '/alipayCashUser/list' //列表接口
      ,where: {
          access_token: layui.data(layui.setter.tableName).access_token
      }
      ,id: 'tableReload'
      ,page: true
      ,cols: [[
        {field: 'id', title: 'ID'}
        ,{field: 'alipayLoginId', title: '支付宝账号'}
        ,{title: '总收款(元)', templet: '<div>{{ d.totalMoney/100 }}</div>' }
        ,{title: '总收款限制(元)', templet: '<div>{{ d.totalMoneyLimit/100 }}</div>'}
        ,{title: '昨日收款(元)', templet: '<div>{{ d.yesterdayMoney/100 }}</div>'}
        ,{title: '今日收款(元)', templet: '<div>{{ d.todayMoney/100 }}</div>'}
        ,{field: 'remark', title: '备注'}
        ,{field: 'status', title: '状态', templet: tplStatus}
        ,{field: 'createUserId', title: '创建人ID'}
        ,{field: 'createTime', title: '创建时间', width: 200, templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
        ,{field: 'edit', title: '操作', fixed: "right", width: 210, toolbar: '#xxpayBar' }
      ]]
      ,skin: 'line'
    });

    //监听工具条
    table.on('tool(XxPay_Mgr_Alipay_Cash_User_dataAll)', function(obj){
      var data = obj.data;
      if(obj.event === 'view'){
          // location.href = layui.setter.baseLocal + "cash_coll/alipay_cash/user/view/id=" + data.id;
          view.xxpayPopup("分账用户详情", "cash_coll/alipay_cash/user/view", {id: data.id}, {btn:false});
      } else if(obj.event === 'edit'){
          // location.href = layui.setter.baseLocal + "cash_coll/alipay_cash/user/edit/id=" + data.id;
          view.xxpayPopup("更新账户模板", "cash_coll/alipay_cash/user/edit", {id: data.id});
      } else if(obj.event === 'del'){
          layer.confirm('确认删除么', function(index){
              admin.req({
                  type: 'get',
                  url: layui.setter.baseUrl + '/alipayCashUser/delete',
                  data: {
                      id: data.id
                  },
                  success: function(res){
                      if(res.code == 0) {
                          layer.msg('删除成功', {
                              icon: 1
                          });
                          table.reload("tableReload");
                      }
                  }
              });
          });
      }

    });

    // 搜索
    var $ = layui.$, active = {
      reload: function(){
        var id = $('#searchId').val();
        //执行重载
        table.reload('tableReload', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {
                id: id,
          }
        });
      }
    };
    $('#search').on('click', function() {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    // 事件处理
    var events = {
        create: function(othis, type){
            view.xxpayPopup("新增分账用户", "cash_coll/alipay_cash/user/add", {null: null});
        }
    };

    $('.layuiAdmin-btns .layui-btn').on('click', function(){
        var othis = $(this)
            ,thisEvent = othis.data('events')
            ,type = othis.data('type');
        events[thisEvent] && events[thisEvent].call(this, othis, type);
    });

    // 渲染表单
    form.render();
  });
</script>